import 'package:flutter/material.dart';
import 'package:get/get.dart';

class MySettingPage extends StatelessWidget {
  static const String route = "/MySettingPage";
  static const String routeID = "/MySettingPage/:id";

  const MySettingPage({super.key});

  // https://dart.dev/tools/diagnostic-messages#unnecessary_non_null_assertion
  buildBackListTileRow(Map? val) {
    return val == null || val["id"] == null
        ? Container()
        : ListTile(
            title: Text("传值 id = ${val["id"]}"),
            subtitle: const Text('Get.back(result: {"success": true}'),
            onTap: () => Get.back(result: {"success": true}),
          );
  }

  @override
  Widget build(BuildContext context) {
    Map? details = Get.arguments;
    Map? parameters = Get.parameters;
    String previousRoute = Get.previousRoute;
    return Scaffold(
        appBar: AppBar(
          title: const Text("GetX"),
          backgroundColor: context.theme.primaryColor,
          leading: GestureDetector(
              onTap: () {
                Get.back(result: {"success": true});
              },
              child: const Icon(Icons.arrow_back_ios)),
        ),
        body: Column(children: [
          ListTile(
            title: const Text("导航-返回- 使用Get.offAll过来的, 无法返回了"),
            subtitle: const Text('Get.back()'),
            onTap: () {
              Get.back();
            },
          ),
          buildBackListTileRow(details),
          buildBackListTileRow(parameters),
          ListTile(
            title: Text("previousRoute = $previousRoute"),
            subtitle: const Text('Get.back(result: {"success": true}'),
            onTap: () => Get.back(result: {"success": true}),
          )
        ]));
  }
}
